package keeto.com.vn.bms.ui.activity;

import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.utils.BMSSharedPreferences;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.widget.ImageView;

public class SplashScreenActivity extends Activity {

	private static final long SPLASH_EXTRA_TIME = 2 * 1000;
	private static final String ACTION_AUTH = null;
	private static final String ACTION_LOGON = null;
	private BMSSharedPreferences preferences;
	public static void actionLaunch(Context context) {
		Intent i = new Intent(context, SplashScreenActivity.class);
		i.setAction(ACTION_AUTH);
		context.startActivity(i);
	}

	public static void actionSplashAndLogon(Context context) {
		Intent intent = new Intent(context, SplashScreenActivity.class);
		intent.setAction(ACTION_LOGON);
		context.startActivity(intent);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_splash_screen);
		ImageView imgLoading= (ImageView)findViewById(R.id.img_loading);
		imgLoading.setBackgroundResource(R.drawable.animation);
		preferences = new BMSSharedPreferences(SplashScreenActivity.this);

		AnimationDrawable frameAnimation = (AnimationDrawable) imgLoading.getBackground();
		frameAnimation.start();

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				switch (preferences.getUserPermission(SplashScreenActivity.this)) {
				case IBMSConfig.KEY_TYPE_DOCTOR:
					BMSChatActivity.actionLaunch(SplashScreenActivity.this);
					break;
				case IBMSConfig.KEY_TYPE_LEADERSHIP:
				case IBMSConfig.KEY_TYPE_ADMIN:
				case IBMSConfig.KEY_TYPE_TECHNICIAL:
				case IBMSConfig.KEY_TYPE_MARKETING:
				case IBMSConfig.KEY_TYPE_CUSTOMER:
					HomeBMSActivity.actionLaunch(SplashScreenActivity.this);
					break;
				default:
					break;
				}
				finish();
			}
		}, SPLASH_EXTRA_TIME);

	}

}
